package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.PageResult;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbBrandExample;
import com.dongdongshop.service.TbBrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TbBrandServiceImpl implements TbBrandService {

    //注入mapper层
    @Autowired
    private TbBrandMapper tbBrandMapper;

    //查询全部品牌列表
    @Override
    public PageResult<TbBrand> TbBrandshowall( Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbBrand> tbBrands = tbBrandMapper.selectByExample(null);
        PageInfo<TbBrand> info = new PageInfo<>(tbBrands);
        return new PageResult<TbBrand>(pageNum,pageSize,info.getTotal(),info.getList(),info.getPages());
    }

    //添加品牌
    @Override
    public void addBrand(TbBrand tbBrand) {
        tbBrandMapper.insertSelective(tbBrand);
    }

    //回显单个品牌数据
    @Override
    public TbBrand showecho(Long id) {
        return tbBrandMapper.selectByPrimaryKey(id);
    }

    //修改单个数据
    @Override
    public void updateBrand(TbBrand tbBrand) {
        tbBrandMapper.updateByPrimaryKeySelective(tbBrand);
    }

    //删除单个数据
    @Override
    public void deleteBrand(Long id) {
        tbBrandMapper.deleteByPrimaryKey(id);
    }

    //删除多个数据
    @Override
    public void deleteallBrand(List<Long> ids) {
        TbBrandExample te = new TbBrandExample();
        TbBrandExample.Criteria criteria = te.createCriteria();
        criteria.andIdIn(ids);
        tbBrandMapper.deleteByExample(te);
    }

    //查询全部品牌列表
    @Override
    public List<TbBrand> TbBrandshow() {
        return tbBrandMapper.selectByExample(null);
    }

}
